package com.example.campus.mapper;

import com.example.campus.pojo.dto.CommentPageQueryDTO;
import com.example.campus.pojo.vo.CommentVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import com.example.campus.pojo.entity.Comment;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CommentMapper {

    Page<CommentVO> getCommentList(CommentPageQueryDTO commentPageQueryDTO);

    @Delete("delete from comment where info_id = #{InfoId}")
    void deleteByInfoId(Long InfoId);

    @Delete("delete from comment where id = #{id}")
    void deleteById(Long id);

    @Select("select c.id, c.user_id, c.info_id, c.content, c.create_time from comment c where c.info_id = #{infoId}")
    List<Comment> getByInfoId(Long infoId);

    @Insert("insert into comment(user_id, info_id, content, create_time) values (#{userId}, #{infoId}, #{content}, #{createTime})")
    void insert(Comment comment);

    @Select("select * from comment where id = #{id};")
    Comment getById(Long id);

    @Select("select count(*) from comment")
    Long getCommentTotal();
}
